#
# Copyright 2009, Jeffrey Palm.
#

#
# Interface for using itunes
#
class ITunes

  # OS constants
  OS_MAC   = 'os.mac'
  OS_OTHER = 'os.other.os'

  attr_reader :name

  def initialize(name)
    @name = name
  end

  def self.new_instance
    return MacInstance.new if os == OS_MAC
    return OtherInstance.new
  end
  
  def to_s
    res  = name
    res += "\n lib = " + library.to_s
  end

  # The interface

  def library    
    throw 'Implement library'
  end

  # Final

  # For testing
  def self.new_mac_instance
    return MacInstance.new
  end
  
  
  # ----------------------------------------------------------------------
  # Private
  # ----------------------------------------------------------------------

  class MacInstance < ITunes
    def initialize
      super OS_MAC
    end
    def library
      File.join(File.join(File.join(ENV['HOME'],'Music'),'iTunes'),'iTunes Music Library.xml') 
    end
  end

  class OtherInstance < ITunes
    def initialize
      super OS_OTHER
    end
  end

  def self.os
    if ENV['HOME'] && ENV['HOME'] != /^\/User/
      return OS_MAC
    end
    return OS_OTHER
  end

end
